package com.yanqu.road.server.cmd.activity.feast;

import com.yanqu.road.entity.activity.feast.config.ShanHeFeastConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ShanHeFeastProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.feast.ShanHeFeastModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.feast.ShanHeFeastMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SHAN_HE_FEAST_MOVE, desc = "移动")
public class FeatMoveCmd extends AbstractCommand {

    private ShanHeFeastProto.FeastPvpPositionTemp positionTemp;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ShanHeFeastProto.FeastMoveReqMsg reqMsg = ShanHeFeastProto.FeastMoveReqMsg.parseFrom(packet.getBytes());
        positionTemp = reqMsg.getPosition();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ShanHeFeastConfig config = ShanHeFeastMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        player.getModule(ShanHeFeastModule.class).move(positionTemp);

    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ShanHeFeastProto.FeastMoveRespMsg.Builder respMsg = ShanHeFeastProto.FeastMoveRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_SHAN_HE_FEAST_MOVE, respMsg);
        }
    }
}
